# coding:utf-8
# name ：YuFuXiao
# date : 2018-9-XX
import json

from flask import Flask  # jsonify  # ,jsonify

# app = Flask(__name__)
# print(f'id为{id(app)}的flask实例化')
# # 导入
# app.config.from_object('config')
#
# from app.web import book


from app import create_app
app = create_app()

if __name__ == '__main__':
    # 方便部署
    app.run(host='0.0.0.0', debug=app.config['DEBUG'], port=8080,threaded=True)
    # threaded 为True会开启多线程
    # processed 为True会开启多进程
    # 调试模式  不用每次都重启

# jsonify:返回json格式的数据

# from flask import make_response  # 可以设置返回的其他信息

# 实现WSGI函数
# from helper import is_isbn_or_key
# from yushu_book import YuShuBook
# from helper import is_isbn_or_key
# from yushu_book import YuShuBook


# from app.web import book

# @app.route('/hello/')  #跳转
# def hello():
#
#     headers = {
#         'content-type':'application/json',
#         # 'location':'https://bing.com',
#     }
#     a_dict = {'yu':22}
#     b_dict = json.dumps(a_dict)
# result = make_response(b_dict,200,headers)  #响应信息返回包含：响应信息、状态信息、头部信息
# return result

# return b_dict,200,headers   #同上
# return b_dict,301,headers   #重定向
# return '<html></html>'  #显示空


# def hellooo():
#     return '<html></html>'  #显示空

# 内视图会用到
# app.add_url_rule('/hello',view_func=hello)


# @app.route('/word')
# def word():
#     return 'word'
#
# @app.route('/hello')
# def hello():
#     return 'hello'

# @app.route('/hello')
# def hello():
#     headers = {
#         'content-type':'application/json'
#     }
#     result = {'yu':21}
#     result1 = json.dumps(result)
#     a_dict = make_response(result1,200,headers)  #响应信息返回包含：响应信息、状态信息、头部信息
#     # return result1,200,headers   #和上面一句意思一样
#     return a_dict

# @app.route('/book/search/<q>/<page>')
# # q：关键字是isbn还是关键字   page：第几页
# def hello(q, page):
#     isbn_or_key = is_isbn_or_key(q)
#     if isbn_or_key == 'isbn':
#         result = YuShuBook.search_by_isbn(q)
#     else:
#         result = YuShuBook.search_by_keyword(q)
#     return jsonify(result)
#     # return json.dumps(result),200,{'contype':'application/json'}
